package com.tg.appcommon.android;
import android.text.TextUtils;

import com.appbase.custom.constant.CommonConstants;
import com.tange.base.toolkit.DESDecrypt;

public class TGDESDecrypt {
    public static TGDESDecrypt getInstance() {
        return SingletonHolder.sInstance;
    }
    private final DESDecrypt mDESDecrypt;
    private TGDESDecrypt() {
        mDESDecrypt = new DESDecrypt();
        mDESDecrypt.setDesKey(CommonConstants.DES_PWD_KEY);
    }

    private static class SingletonHolder {
        private static final TGDESDecrypt sInstance = new TGDESDecrypt();
    }

    public void setDesKey(String desKey) {
        if (!TextUtils.isEmpty(desKey)) {
            mDESDecrypt.setDesKey(desKey);
        }
    }

    public String decrypt(String input){
        String result = "";
        try {
            result = mDESDecrypt.decrypt(input).trim();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public String encrypt(String input){
        String result = "";
        try {
            result = mDESDecrypt.encrypt(input);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
